//
//  ViewController.m
//  I-go
//
//  Created by mac on 15/4/3.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "ViewController.h"


#define i_go 20  //棋盘格子宽度
#define temp 15 ///设置一行和一排个格子数量
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    CGFloat onex=80;
//    CGFloat oney=80;
    

    CGFloat onex=(self.view.frame.size.width-temp*i_go)/2;//第一个格子到x,y,这样可以调节个数
    CGFloat oney=(self.view.frame.size.height-temp*i_go)/2;
//    int temp=(self.view.frame.size.width-2*onex)/i_go;
//    NSLog(@"%i",temp);
       
    
    int i_gonumber=temp*temp;
    for (int i=0; i<i_gonumber; i++) {
        CGFloat x=onex+i_go*(i%temp);//格子的坐标x＝第一个格子到x＋格子宽度*（第几个格子％一行对格子数）
        CGFloat y=oney+i_go*(i/temp);
        int k=(x+y)/20;
        NSLog(@"%i",k);
        if ((k%2)==0) {  //判断格子是黑色还是红色并且添加到视图中
            UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(x, y, i_go, i_go)];
            view1.backgroundColor=[UIColor redColor];
            [self.view addSubview:view1];
    } else  {
        UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(x, y, i_go, i_go)];
        view1.backgroundColor=[UIColor blackColor];
        [self.view addSubview:view1];
    }

}

}

@end
